package com.example.shop.controller;

import com.example.shop.entity.Organizationtype;
import com.example.shop.service.OrganizationtypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName OrganizationtypeController
 * @Description TODO
 * @Author 萍
 * @Date 2025/3/26 10:23
 */

@RestController
@RequestMapping("/organizationtype")
public class OrganizationtypeController {

    @Autowired
    private OrganizationtypeService organizationtypeService;

    /**
     * 通过ID查询单条数据
     *
     * @param organizationtypeid 主键
     * @return 实例对象
     */
    @GetMapping("/{organizationtypeid}")
    public ResponseEntity<Organizationtype> queryById(@PathVariable Integer organizationtypeid) {
        Organizationtype organizationtype = organizationtypeService.queryById(organizationtypeid);
        if (organizationtype == null) {
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(organizationtype);
    }

    /**
     * 查询所有数据
     *
     * @return 实例对象列表
     */
    @GetMapping("/")
    public ResponseEntity<List<Organizationtype>> queryAll() {
        List<Organizationtype> organizationtypeList = organizationtypeService.queryAll();
        return ResponseEntity.ok(organizationtypeList);
    }

    /**
     * 新增数据
     *
     * @param organizationtype 实例对象
     * @return 实例对象
     */
    @PostMapping("/")
    public ResponseEntity<Organizationtype> insert(@RequestBody Organizationtype organizationtype) {
        Organizationtype insertedOrganizationtype = organizationtypeService.insert(organizationtype);
        return ResponseEntity.ok(insertedOrganizationtype);
    }

    /**
     * 修改数据
     *
     * @param organizationtype 实例对象
     * @return 实例对象
     */
    @PutMapping("/")
    public ResponseEntity<Organizationtype> update(@RequestBody Organizationtype organizationtype) {
        Organizationtype updatedOrganizationtype = organizationtypeService.update(organizationtype);
        return ResponseEntity.ok(updatedOrganizationtype);
    }

    /**
     * 通过主键删除数据
     *
     * @param organizationtypeid 主键
     * @return 是否成功
     */
    @DeleteMapping("/{organizationtypeid}")
    public ResponseEntity<Boolean> deleteById(@PathVariable Integer organizationtypeid) {
        boolean isDeleted = organizationtypeService.deleteById(organizationtypeid);
        return ResponseEntity.ok(isDeleted);
    }
}